package com.glory.brepda.adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.activity.mfg.BomInfoCheckActivity;
import com.glory.brepda.activity.tool.ToolBomDeleteActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.BomInfoEntity;
import com.glory.brepda.entity.ToolBomLineEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.adapter.Call;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_Utils;

import org.json.JSONObject;

import java.util.List;

public class ToolBomInfoListAdapter extends BaseQuickAdapter<ToolBomLineEntity.ResultBean, BaseViewHolder> {

    Context context;
    private OnItemClickListener onItemClickListener;

    public ToolBomInfoListAdapter(@Nullable List<ToolBomLineEntity.ResultBean> data, Context context) {
        super(R.layout.item_tool_bom_info_adapter,data);
        this.context = context;

    }

    @Override
    protected void convert(BaseViewHolder helper, ToolBomLineEntity.ResultBean item) {
//        helper.setText(R.id.tvMaterialDesc,item.getMATERIAL_DESC());
//        helper.setText(R.id.tvMaterialType,item.getMATERIAL_TYPE());
//        helper.setText(R.id.tvWorkStepDesc,item.getWORK_STEP_DESC());
        helper.setText(R.id.tvToolSpec,item.getTOOLSPEC());
        helper.setText(R.id.tvToolLife,item.getTOOLLIFE());
        helper.getView(R.id.delete).setOnClickListener(view -> {
            // 创建一个AlertDialog.builder对象
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("确认删除");
            builder.setMessage("你确定要删除这个项目吗？");
            builder.setPositiveButton("确定", (dialog, which) -> {
                if ( onItemClickListener != null) {
                    onItemClickListener.onItemClick(this, view, helper.getAdapterPosition());
                }
            });
            builder.setNegativeButton("取消", (dialog, which) -> {
                // 用户点击了取消按钮，不做任何事情
                dialog.dismiss();
            });

            // 显示弹窗
            AlertDialog dialog = builder.create();
            dialog.show();
        });
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

}
